//
//  ToolBarView.m
//  Flava
//
//  Created by Ug-Code on 13-8-16.
//  Copyright (c) 2013年 UgCode. All rights reserved.
//

#import "ToolBarView.h"

@implementation ToolBarView

#define kToolBar_X 0
#define kToolBar_Y [UGDevice windowHeight]-kToolBar_H-20-5
#define kToolBar_Y_7 [UGDevice windowHeight]-kToolBar_H
#define kToolBar_W 320
#define kToolBar_H 49

@synthesize
syncDate = _syncDate;

- (id)init
{
    self = [super init];
    if (self) {
		[UGDevice windowHeight];
		if ([UGDevice systemVersion] >= 7) {
			self.frame = CGRectMake(kToolBar_X, kToolBar_Y_7, kToolBar_W, kToolBar_H);
		} else {
			self.frame = CGRectMake(kToolBar_X, kToolBar_Y, kToolBar_W, kToolBar_H);
		}
		_settingsButton = [[UGButton alloc] init];
		_syncView = [[UGView alloc] initWithFrame:CGRectMake(60, 0, 260, 49)];
		[self addSubview:_syncView];
		_syncButton = [[UGButton alloc] init];
		_syncIndicator = [[UGIndicatorView alloc] init];
		_syncDate = [[NSDate alloc] init];
		_syncDateLable = [[UILabel alloc] init];
		[self createSettingButton];
		[self createSyncButton];
		[self createSyncIndicator];
		[self createSyncDate];
		[self createSyncDateLable];
    }
    return self;
}

- (void)syncStart
{
	static BOOL isSync = NO;
	if ((isSync = !isSync)) {
		[_syncIndicator startAnimation];
		_syncDateLable.text = @"同步化进行中...";
	} else {
		[_syncIndicator stopAnimation];
		_syncDateLable.text = [NSString stringWithFormat:@"最后同步日期\n2013-8-13 下午7:45"];
	}
}

- (void)createSettingButton
{
	_settingsButton.frame = CGRectMake(0, 0, 60, 49);
	[_settingsButton setNormalImage:[[UIImage imageNamed:@"btn_dark_n.png"]
									 stretchableImageWithLeftCapWidth:1 topCapHeight:1]];
	[_settingsButton setHighlightedImage:[[UIImage imageNamed:@"btn_dark_h.png"]
										  stretchableImageWithLeftCapWidth:1 topCapHeight:1]];
	[_settingsButton setImage:[UIImage imageNamed:@"btn_icon_settings.png"] forState:UIControlStateNormal];
	_settingsButton.adjustsImageWhenHighlighted = NO;
	[self addSubview:_settingsButton];
}

- (void)createSyncButton
{
	[_syncButton setNormalImage:[[UIImage imageNamed:@"btn_dark_n.png"]
								 stretchableImageWithLeftCapWidth:1 topCapHeight:1]];
	[_syncButton setHighlightedImage:[[UIImage imageNamed:@"btn_dark_h.png"]
									  stretchableImageWithLeftCapWidth:1 topCapHeight:1]];
	_syncButton.frame = CGRectMake(0, 0, 260, 49);
	[_syncButton addTarget:self action:@selector(syncStart) forControlEvents:UIControlEventTouchUpInside];
	[_syncView addSubview:_syncButton];
}

- (void)createSyncIndicator
{
	_syncIndicator.image = [UIImage imageNamed:@"btn_icon_sync.png"];
	_syncIndicator.frame = CGRectMake(15, 10, 30, 30);
	_syncIndicator.userInteractionEnabled = NO; //接受点击事件
//	[_syncView addSubview:_syncIndicator];
	[_syncButton addSubview:_syncIndicator];
}

- (void)createSyncDate
{
	
}

- (void)createSyncDateLable
{
	_syncDateLable.frame = CGRectMake(59, 12, 120, 27);
	_syncDateLable.font = [UIFont systemFontOfSize:12];
	_syncDateLable.textColor = [UIColor grayColor];
	_syncDateLable.backgroundColor = UGAlphaColor;
	_syncDateLable.text = [NSString stringWithFormat:@"最后同步日期\n2013-8-13 下午7:45"];
	_syncDateLable.numberOfLines = 2;
//	[_syncView addSubview:_syncDateLable];
	_syncDateLable.userInteractionEnabled = NO;
	[_syncButton addSubview:_syncDateLable];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
